<?php
define('PATH_BASE', dirname(__FILE__) . "/../../..");
require_once PATH_BASE . "/include/functions.inc.php";
require_once PATH_BASE . "/include/easoftwarebussinesobject.php";
require_once PATH_BASE . "/bo/BoContabilidad.php";
require_once PATH_BASE . "/bo/BoCobros.php";
$db = DbManager::getMe();

/**
 * draw debug
 * @param type $ThisVar
 * @param type $VariableName
 * @param type $ShowWhat 
 */
function drawDebug($ThisVar, $VariableName = "", $ShowWhat = 0) {

    $strType = gettype($ThisVar);
    $strPreOpen = "";
    $strPreClose = "";
    if (!is_string($ThisVar)) {
        $strPreOpen = "<pre>";
        $strPreClose = "</pre>";
    }

    echo "\n<hr>";
    if (!empty($VariableName))
        echo "<b><i> $VariableName</b></i> ";
    echo "Var  Type of var = <b>" . $strType . "</b><br><br>\n{$strPreOpen}";
    if ($ShowWhat == 0) {
        if (is_bool($ThisVar))
            print_r(($ThisVar) ? "true" : "false");
        else
            print_r($ThisVar);
    }

    else if ($ShowWhat == 1) {
        print_r(array_values($ThisVar));
    } else if ($ShowWhat == 2) {
        print_r(array_keys($ThisVar));
    }
    print_r("<hr>{$strPreClose}\n");
}

/**
 * 
 * @param type $db
 * @param type $intSelectedID 
 */
function drawEmpresa($db, $intSelectedID = 0) {

    $strSelectedID = "";
    ?>
    <b>Seleccione Empresa:</b>
    <select name="sltEmpresa">
        <?php
        $strQuery = "SELECT * FROM cllg_contab_empresa";
        $qTMP = $db->query($strQuery);

        while ($rTMP = $db->fetch_array($qTMP)) {
            $strSelectedID = ($intSelectedID == $rTMP["codigo"] ) ? "selected" : "";
            ?>
            <option value="<?php print $rTMP["codigo"]; ?>" <?php print $strSelectedID; ?>><?php print $rTMP["nombre"]; ?></option>
            <?php
        }
        $db->free_result($rTMP);
        ?>
    </select>
    <?php
}

/**
 * 
 * @param type $db
 * @param type $strNombre
 * @param type $intSelectedID 
 */
function fntMovimientoDrawEmpresa($db, $strNombre = "", $intSelectedID = 0) {

    $strSelectedID = "";
    ?>
    <b>Seleccione Empresa:</b>
    <select name="slt<?php print $strNombre; ?>Empresa">
        <?php
        $strQuery = "SELECT * FROM cllg_contab_empresa";
        $qTMP = $db->query($strQuery);

        while ($rTMP = $db->fetch_array($qTMP)) {
            $strSelectedID = ($intSelectedID == $rTMP["codigo"] ) ? "selected" : "";
            ?>
            <option value="<?php print $rTMP["codigo"]; ?>" <?php print $strSelectedID; ?>><?php print $rTMP["nombre"]; ?></option>
            <?php
        }
        $db->free_result($rTMP);
        ?>
    </select>
    <?php
}

/**
 *
 * @param type $db
 * @param type $strNombre
 * @param type $intSelectedID 
 */
function fntEmpresasDraw($db, $strNombre = "", $intSelectedID = 0) {

    $strQuery = "SELECT * FROM cllg_contab_empresa";
    $qTMP = $db->query($strQuery);
    $intNumRows = $db->num_rows;

    if ($intNumRows == 1) {

        while ($rTMP = $db->fetch_array($qTMP)) {
            ?>
            <b>Empresa:</b>
            <?php
            print $rTMP["nombre"];
            ?>
            <input type="hidden" name="<?php print $strNombre; ?>" value="<?php print $rTMP["codigo"]; ?>">
            <?php
        }
    } else {
        $strSelectedID = "";
        ?>
        <b>Seleccione Empresa:</b>
        <select name="<?php print $strNombre; ?>">
            <option value="0"></option>
            <?php
            while ($rTMP = $db->fetch_array($qTMP)) {
                $strSelectedID = ($intSelectedID == $rTMP["codigo"] ) ? "selected" : "";
                ?>
                <option value="<?php print $rTMP["codigo"]; ?>" <?php print $strSelectedID; ?>><?php print $rTMP["nombre"]; ?></option>
                <?php
            }
            ?>
        </select>
        <?php
    }
    $db->free_result($rTMP);
}
?>